package com.zhiche.lisa.oms.controller;

import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.oms.dao.model.OrderAssign;
import com.zhiche.lisa.oms.service.ILocationService;
import com.zhiche.lisa.oms.service.IOrderAssignService;
import com.zhiche.lisa.oms.vo.LocationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/orderAssign")
@Api(value = "/orderAssign", description = "订单下发",tags={"订单下发"})
public class OrderAssignController {
    private static final Logger LOGGER = LoggerFactory.getLogger(LocationController.class);

    @Autowired
    private IOrderAssignService orderAssignService;

    @GetMapping(value="/getOrderAssignByConsignCode/{consignCode}")
    @ApiOperation(value = "根据(委托单号)得到订单下发数据", notes = "根据委托单号(consign_code)得到订单下发表的数据", produces = MediaType.APPLICATION_JSON_VALUE,response = RestfulResponse.class)
    public RestfulResponse<OrderAssign> getOrderAssignByConsignCode(@PathVariable("consignCode") String consignCode) {
        LOGGER.info("OrderAssignController.getOrderAssignByConsignCode（根据委托单号(consign_code)得到订单下发表的数据） params : {} {}", consignCode);
        RestfulResponse result = new RestfulResponse();
        try {
            OrderAssign orderAssignVal = orderAssignService.getOrderAssignByConsignCode(consignCode);
            result = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(),orderAssignVal);
        } catch (BaseException e) {
            LOGGER.error("OrderAssignController.getOrderAssignByConsignCode ERROR... ", e);
            result = new RestfulResponse<>(e.getCode(), e.getMessage(), null);
        }
        return result;
    }
}
